//
//  DrawerController.m
//  MyCloudMusic
//
//  Created by pub on 2024/6/10.
//

#import "DrawerController.h"

@interface DrawerController ()

@end

@implementation DrawerController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setBackgroundColor:[UIColor colorSlideBackground]];
    
    [self initScrollSafeArea];
    
    [self initUserView];
    
}


- (void)initUserView{
    MyRelativeLayout *userContainer = [MyRelativeLayout new];
    
    userContainer.myWidth = MyLayoutSize.fill;
    userContainer.myHeight = MyLayoutSize.wrap;
    userContainer.padding = UIEdgeInsetsMake(PADDING_OUTER, PADDING_OUTER, PADDING_OUTER, PADDING_OUTER);
    
    UITapGestureRecognizer *tap = [UITapGestureRecognizer new];
    
    [tap addTarget:self action:@selector(userCenterClick:)];
    [userContainer addSubview:self.iconView];
    [userContainer addSubview:self.nickNameView];
    [userContainer addGestureRecognizer:tap];
    
    [userContainer addSubview:self.iconView];
    UIImageView *moreView = [ViewFactoryUtil moreIconView];
    moreView.centerXPos.equalTo(@(0));
    moreView.leftPos.equalTo(self.nickNameView.rightPos).offset(3);
    [userContainer addSubview:moreView];
    
    [userContainer addSubview:self.scanView];
    [self.container insertSubview:userContainer atIndex:0];
    self.contentContainer.padding = UIEdgeInsetsMake(PADDING_OUTER, PADDING_OUTER, PADDING_OUTER, PADDING_OUTER);
    
    self.contentContainer.subviewSpace = PADDING_OUTER;
}

- (void)userCenterClick:(UITapGestureRecognizer *)tap{
    [self closeDrawer];
    
    
}

- (void)closeDrawer{
    [self dismissViewControllerAnimated:YES completion:^{
            
    }];
}

- (UIImageView *)iconView{
    if(!_iconView){
        _iconView = [UIImageView new];
        _iconView.myWidth = 30;
        _iconView.myHeight = 30;
        _iconView.image = R.image.defaultAvatar;
        [_iconView smallRadius];
        _iconView.centerYPos.equalTo(@(0));
        _iconView.myLeft = 0;
        _iconView.clipsToBounds = YES;
        _iconView.contentMode = UIViewContentModeScaleAspectFill;
    }
    
    return _iconView;
}

- (UILabel *)nickNameView{
    if(!_nickNameView){
        _nickNameView = [UILabel new];
        _nickNameView.myWidth = MyLayoutSize.wrap;
        _nickNameView.myHeight = MyLayoutSize.wrap;
        _nickNameView.text = @"昵称";
        _nickNameView.font = UIFontMake(16);
        _nickNameView.textColor = [UIColor colorOnBackground];
        _nickNameView.centerYPos.equalTo(@(0));
        _nickNameView.leftPos.equalTo(self.iconView.rightPos).offset(16);
        
    }
    
    return _nickNameView;
}

- (UIButton *)scanView{
    if(!_scanView){
        _scanView = [ViewFactoryUtil buttonWithImage:R.image.scan];
        _scanView.tintColor = [UIColor colorOnBackground];
        _scanView.centerYPos.equalTo(@(0));
        _scanView.rightPos.equalTo(@(0));
        [_scanView addTarget:self action:@selector(onScanClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _scanView;
}

@end
